#include <iostream>
#include <cstring>
#include <string>
#include <vector>
// 将str以sep为分隔符将该字符串分隔成多个子串保存到result中
// new...music..pop--->new    music    pop
size_t split(std::string &str, const std::string &sep, std::vector<std::string> &result)
{
    int pos = 0, idex = 0; // pos分隔符开始位置，ide从哪开始分隔
    while (idex < str.size())
    {
        pos = str.find(sep,idex);
        if (pos == std::string::npos)
        {
            // 直接将整个字符串添加进容器
            result.push_back(str.substr(idex,pos-idex));
            return result.size();
        }
        // 找到第一个分隔符
        // 判断该分隔符位置是否与idex相等，相等说明没有找到有效字符串
        if (pos == idex)
        {
            idex = pos + sep.size();
            continue;
        }
        std::string tem = str.substr(idex, pos - idex);
        result.push_back(tem);
        idex = pos + sep.size();
    }
        return result.size();
}

int main()
{
    std::string msg = "...new...music..pop";
    std::vector<std::string> v;
    size_t n = split(msg,".",v);
    for(auto& e:v)
    {
        std::cout<<e<<std::endl;
    }
    return 0;
}